package com.baidu.location;

import android.location.GpsSatellite;
import android.location.GpsStatus;
import android.location.GpsStatus.Listener;
import android.location.GpsStatus.NmeaListener;
import android.location.LocationManager;
import java.util.Iterator;
import java.util.List;

final class o
  implements GpsStatus.Listener, GpsStatus.NmeaListener
{
  public final void onGpsStatusChanged(int paramInt)
  {
    if (n.b(this.a) == null)
      return;
    switch (paramInt)
    {
    case 3:
    default:
      return;
    case 2:
      n.a(this.a, null);
      n.b(this.a, false);
      n.a(0);
      return;
    case 4:
    }
    ak.e();
    if (n.c(this.a) == null)
    {
      n.a(this.a, n.b(this.a).getGpsStatus(null));
      Iterator localIterator = n.c(this.a).getSatellites().iterator();
      paramInt = 0;
      label113: if (!(localIterator.hasNext()))
        break label165;
      if (!(((GpsSatellite)localIterator.next()).usedInFix()))
        break label230;
      paramInt += 1;
    }
    while (true)
    {
      while (true)
      {
        break label113:
        n.b(this.a).getGpsStatus(n.c(this.a));
      }
      label165: ak.e();
      if ((n.g() >= 3) && (paramInt < 3))
        n.b(this.a, System.currentTimeMillis());
      if (paramInt < 3)
        n.b(this.a, false);
      if ((n.g() <= 3) && (paramInt > 3))
        n.b(this.a, true);
      n.a(paramInt);
      label230: return;
    }
  }

  public final void onNmeaReceived(long paramLong, String paramString)
  {
    if (!(ak.ae))
      ak.d = 0;
    do
      return;
    while ((paramString == null) || (paramString.equals("")) || (paramString.length() < 9) || (paramString.length() > 150) || (!(this.a.e())));
    paramLong = System.currentTimeMillis();
    new StringBuilder("gps manager onNmeaReceived : ").append(paramLong).append(" ").append(paramString);
    ak.e();
    if ((paramLong - n.d(this.a) > 400L) && (n.e(this.a)) && (n.f(this.a).size() > 0));
    try
    {
      q localq = new q(this.a, n.f(this.a), n.g(this.a), n.h(this.a), n.i(this.a), 0);
      if (q.a(localq))
      {
        int i = q.b(localq);
        ak.d = i;
        if (i > 0)
          n.a(String.format("&nmea=%.1f|%.1f&g_tp=%d", new Object[] { Double.valueOf(q.c(localq)), Double.valueOf(q.d(localq)), Integer.valueOf(ak.d) }));
        n.f(this.a).clear();
        n.a(this.a, n.b(this.a, n.c(this.a, null)));
        n.c(this.a, false);
        if (!(paramString.startsWith("$GPGGA")))
          break label340;
        n.c(this.a, true);
        n.a(this.a, paramString.trim());
        n.c(this.a, System.currentTimeMillis());
        return;
      }
      ak.d = 0;
      label340: ak.e();
    }
    catch (Exception localException)
    {
      while (true)
      {
        do
          while (true)
          {
            while (true)
              ak.d = 0;
            if (!(paramString.startsWith("$GPGSV")))
              break;
            n.f(this.a).add(paramString.trim());
          }
        while (!(paramString.startsWith("$GPGSA")));
        n.c(this.a, paramString.trim());
      }
    }
  }
}